#ifndef EDITITEM_H
#define EDITITEM_H

#include <QtGui/QWidget>
#include "ui_edititem.h"
#include "config.h"
#include "DB_Manager.h"
#include "appini.h"
#include <QSqlRelationalDelegate>
#include "gregion.h"
#include "DataExportDialog.h"
#include "CalendarStructure.h"
#include "dlgattributi.h"
#include "htmlgenerator.h"


static inline bool tumpbweb( QPixmap pic , QString file )
{
    qt_unlink(file);
    
    QPixmap pan = pic.scaled(100,70,Qt::KeepAspectRatioByExpanding);
    if (pan.height() > 70) {
            const int dasopra = pan.height() / 2 - 35;
            QPixmap der = pan.copy (0,dasopra,100,70);
            QPixmap der1 = der.scaled(100,70,Qt::IgnoreAspectRatio);
            return der1.save(file,"JPG",60);
    } else {
    return pan.save(file,"JPG",60);
    }
    
}





/* delegate mapping  to QDataWidgetMapper */

class EditMapDelegate : public QItemDelegate
{
    Q_OBJECT
	
public:
    EditMapDelegate(DB_Manager * dbin , QObject *parent = 0 );
    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
    DB_Manager * db;
};



class EditItem : public QWidget , public Ui::EditItem
{
    Q_OBJECT

public:
    EditItem( DB_Manager * dbin , uint numero , int dbtype_id = 0);
    bool work( uint check_nr );
    ~EditItem();
    void closeEvent( QCloseEvent* e );
    uint m_id;
    uint dbpointer;
    QSqlQueryModel *mod;
    QSqlRecord rec;
    QDataWidgetMapper *mapper;
    QLineEdit *Tid0;   ////// 
    QLineEdit *Tid1;   ////// 
    QLineEdit *Tid2;   ////// 
    QLineEdit *Tid90;   ////// 
    void Loaddata();
    int TIPO;
    QSettings setter;
    QFileInfo zipetfile;
    QString WEBPOSTINGPATH;
    QString ImageListStream;
    HtmlGenerator *proc_document_generator;
    //////HtmlDoc *generator;
    bool pdfready;
    QPixmap orilogo;
    QPixmap logosmall;
    QMap<QString,QTextDocument*> Xpdf;
    QMap<QString,SPics> Fimg;
    bool incomming_pdfs;
    void  append_pic ( const QString def , QPixmap pic  );
    void  fillImage( QTextDocument * doc );
signals:
   void ReloadMain();
   void EC_Close(uint);
public slots:
    void on_Paesibutton_clicked();
    void on_SaveButton_clicked();
    void on_generateweppdf_clicked();
    void on_Undoedit_clicked();
    void on_Occupazioni_clicked();
    void on_Att_50_clicked();
    void on_Att_60_clicked();
    void on_Att_70_clicked();
    void on_RemOggetto_clicked();
    void on_checkwepage_clicked();
    void on_ReloadDataCurrent_clicked();
    void PdfPrint();
    void on_TrovaloRete_clicked();
    void on_MailOpenOggetto_clicked();
    void on_WebOpenOggetto_clicked();
    void on_CercaTiTurismo_clicked();
    void proc_ending( bool e , int n);
    void on_sender_upload_clicked();
    void OpenWeb();
    void childFinished( uint i );
    void childerror( uint i );

private:
    uint db_id;
    void PrintMenu();
    /////Ui_EditItem ui;
    DB_Manager *db;
    
};




/*

void EditItem::on_Occupazioni_clicked()
{
	Calendario_Occupazioni *Cal = new Calendario_Occupazioni(this);
	   int res = Cal->exec();
		 qDebug() << "### res" << res;
		 Cal->deleteLater();
	
}


*/













#endif // EDITITEM_H
